package edu.cuit.avatar.loop;

import java.util.Scanner;

/**
 * 5道减法运算题并统计
 */
public class SubtractionQuizLoop {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        final int NUMBER_OF_QUESTION = 5;
        //统计正确数
        int correctCount = 0;

        //循环计数器
        int count = 0;

        while(count < NUMBER_OF_QUESTION){
            int number1 = (int)(Math.random() * 100);
            int number2 = (int)(Math.random() * 100);

            if(number1 < number2){
                int temp = number1;
                number1 = number2;
                number2 = temp;
            }
            System.out.printf("%2d - %2d = ", number1, number2);
            int answer = input.nextInt();
            //统计
            if(answer == number1 - number2)
                correctCount++;

            //控制循环是否继续的迭代部分
            count++;
        }
        System.out.println("正确数:" + correctCount);
    }
}
